<?php
include "../../../lib/list.php";
if ($_GET['s_no']){
	$s_no = $_GET['s_no'];
	$sear_char .= " AND uatp_stock.s_no = $s_no";
}

if ($_POST['s_no']){
	$s_no = $_POST['s_no'];
	$sear_char .= " AND uatp_stock.s_no = $s_no";
}
if ($_GET['sg_no'])$sg_no = $_GET['sg_no'];
if ($_POST['sg_no'])$sg_no = $_POST['sg_no'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<link rel="stylesheet" href="../../../css/list.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/insert.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/table.blue.sorter.css" type="text/css" media="print, projection, screen"></link>
<link rel="stylesheet" href="../../../css/jquery.tablesorter.pager.css"	type="text/css" media="print, projection, screen"></link>
<script type="text/javascript" src="../../../js/jquery-1.2.6.js"></script>
<script type="text/javascript"	src="../../../js/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" src="../../../js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="../../../js/list.js"></script>
<script type="text/javascript">
function page_move(page){
			document.view.page.value = page;
			document.view.target = 'right';
			document.view.action = 'view.php';
			document.view.method = 'post';
			document.view.submit();
}

$(function(){
	$("select[name='sg_no']").change(function(){
	    var sg_no = $("select[name='sg_no']").attr('value');
	    $.get('../../../lib/select.php?sg_no='+sg_no,function(res){
	        $("select[name='s_no']").html(res);
	    });
	});
});


function movepage(url,get,value){
	var sg_no = document.getElementsByName('sg_no')[0].value;
	location.href = url+"?"+get+"="+value+"&sg_no="+sg_no;
}


	</script>
</head>
<body>
	<div style="width: 1024px; padding: 10px;">
		<div
			style="border-bottom: 1px solid #e8e8e8; text-align: left; font-size: 12px; margin-bottom: 12px; color: #9a9a9a">:::
			마스터 관리&nbsp;⇒&nbsp;재고보기</div>
			<div style="float: left; padding: 5px; font-size:11px;">
						<select name='sg_no' class="default">
						<option value="-3">:: 점포그룹 선택 ::</option>
						<?
						$qry = "SELECT * FROM uatp_shopgroup order by no DESC";
						$query = DBquery($qry);
						while($list = mysql_fetch_array($query)){
							?>
						<option value="<?=$list['no']?>"<?if($list['no']==$sg_no)echo " selected";?>><?=$list['name']?></option>
						<?
						}
						mysql_close();
						?>
						</select>
						
						<select name='s_no' class="default" onChange="movepage('view.php','s_no',this.value);";>
							<option value="">:: 점포 선택 ::</option>
							<?
							if($sg_no){
								$qry = "SELECT * FROM uatp_shopinfo WHERE sg_no = $sg_no order by no DESC";
								$query = DBquery($qry);
								while($list = mysql_fetch_array($query)){
									?>
														<option value="<?=$list['no']?>"<?if($list['no']==$s_no)echo " selected";?>><?=$list['name']?></option>
														<?
														}
														mysql_close();
							}
							?>
						</select>
			</div>
		<form name="view" method="post">
			<input type="hidden" value="<?=$s_no?>" name="s_no" />
			<input type="hidden" value="<?=$sg_no?>" name="sg_no" />
			<input type="hidden" value="" name="page" />
			<table cellspacing="1" class="tablesorter">
				<thead>
					<tr>
						<th width="30px">no</th>
						<th>점포그룹</th>
						<th>점포명</th>
						<th>바코드</th>
						<th>상품명</th>
						<th>갯수</th>
						<th>입고단가</th>
						<th>금액</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th width="30px">no</th>
						<th>점포그룹</th>
						<th>점포명</th>
						<th>바코드</th>
						<th>상품명</th>
						<th>갯수</th>
						<th>입고단가</th>
						<th>금액</th>
					</tr>
				</tfoot>
				<tbody>
			<?php
			$page=$_POST['page'];
			$sql = "SELECT uatp_product.productname, uatp_product.buyingprice, uatp_product.barcode, 
								uatp_shopinfo.name AS 'shopname', uatp_stock.count, uatp_shopgroup.name AS 'groupname'
								FROM uatp_stock 
								INNER JOIN uatp_shopinfo ON uatp_stock.s_no = uatp_shopinfo.no
								INNER JOIN uatp_product ON uatp_stock.p_no = uatp_product.no
								INNER JOIN uatp_shopgroup ON uatp_shopinfo.sg_no = uatp_shopgroup.no
								WHERE 1 $sear_char";
			$total = DBnumrows($sql);
			
			$scale=15;
			if ($page == ''){
				$page=1;
			}
			
			$cpage = intval($page);//현재 페이지
			$totalpage = intval($total/$scale); //전체 페이지 갯수
			if ($totalpage*$scale != $total)
			$totalpage = $totalpage + 1;
			
			if ($cpage ==1) {
				$cline = 0 ;
			} else {
				$cline = ($cpage*$scale) - $scale ;
			}
			
			$limit=$cline+$scale;
			
			if ($limit >= $total)
			$limit=$total;
			$scale1 = $limit - $cline;
			$query = $sql." ORDER BY uatp_stock.s_no DESC LIMIT $cline, $scale1";
			$result = DBquery($query);
			for($i=1; $list = mysql_fetch_array($result); $i++){
				$bunho = $total - ( $i + $cline) + 1;
										?>
							<tr>
								<td align="center" width="30px"><?=$bunho?></td>
								<td><?=$list['groupname']?></td>
								<td><?=$list['shopname']?></td>
								<td><?=$list['barcode']?></td>
								<td><?=$list['productname']?></td>
								<td style="text-align:right;"><?=$list['count']?></td>
								<td style="text-align:right;"><?=$list['buyingprice']?></td>
								<td style="text-align:right;"><?=$list['count']*$list['buyingprice']?></td>
							</tr>
<?php 
	}
	mysql_free_result($result);
?>
			</tbody>
			</table>
			<div style="float:left;width:500px;"><?php page_avg($totalpage,$cpage);?></div>
			<div style="float:right;text-align:right;width:500px;">
			<input type="button" class="button blue small" value="갱신하기 " onclick="page_move(<?=$page?>);"/>
			</div>
		</form>
	</div>
</body>
</html>